package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.common.validation.ValidationHelper;
import com.meituan.catering.management.shop.biz.model.ShopBO;
import com.meituan.catering.management.shop.dao.model.ShopDO;


/**
 * 从其他数据模型向门店DO的转换器
 */
public abstract class ShopDOConverter {
    /**
     * 创建门店 转换类
     */
    public static ShopDO fromBO(ShopBO shopBO) {
        if (shopBO == null) {
            return null;
        } else {
            ValidationHelper.validate(shopBO);
            ShopDO shopDO = new ShopDO();
            shopDO.setId(shopBO.getId());
            shopDO.setTenantId(shopBO.getTenantId());
            shopDO.setCreatedBy(shopBO.getAuditing().getCreatedBy());
            shopDO.setCreatedAt(shopBO.getAuditing().getCreatedAt());
            shopDO.setLastModifiedBy(shopBO.getAuditing().getLastModifiedBy());
            shopDO.setLastModifiedAt(shopBO.getAuditing().getLastModifiedAt());
            shopDO.setBusinessNo(shopBO.getBusinessNo());
            shopDO.setName(shopBO.getName());
            /*
             * 直接设置枚举名（string） 存入数据库
             */
            shopDO.setBusinessType(String.valueOf(shopBO.getBusinessType()));

            shopDO.setContactTelephone(shopBO.getContact().getTelephone());
            shopDO.setContactCellphone(shopBO.getContact().getCellphone());
            shopDO.setContactName(shopBO.getContact().getName());
            shopDO.setContactAddress(shopBO.getContact().getAddress());
            /*
             * 直接设置枚举名 存入数据库
             */
            shopDO.setManagementType(String.valueOf(shopBO.getManagementType()));
            shopDO.setOpeningHoursOpenTime(shopBO.getOpenTime());
            shopDO.setOpeningHoursCloseTime(shopBO.getCloseTime());

            shopDO.setBusinessArea(shopBO.getBusinessArea());
            shopDO.setComment(shopBO.getComment());
            shopDO.setEnabled(shopBO.getEnabled()?"1":"0");

            shopDO.setVersion(shopBO.getVersion());
            return shopDO;
        }
    }

}
